import requests

class IhrmEmployApi():
    # 添加员工
    @classmethod
    def add_emp(cls, header, json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        resp = requests.post(url = url, headers= header, json= json_data)
        return resp

    # 查询员工
    @classmethod
    def quary_emp(cls, emp_id, header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.get(url=url, headers=header)
        return resp

    #修改员工
    @classmethod
    def modify_emp(cls, emp_id, header, json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.put(url = url, headers= header, json= json_data)
        return resp

    #删除员工
    @classmethod
    def del_emp(cls, emp_id, header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.delete(url = url, headers= header)
        return resp

if __name__ == '__main__':
    header = {"Content-Type": "application/json", "Authorization": "f70bf5ef-ab33-4ac1-a857-0015e4bdd222"}
    json_data = {"username": "业务猪001","mobile": "13978442714", "workNumber": "9527"}
    resp = IhrmEmployApi.add_emp(header, json_data)
    print("添加", resp.json())

    emp_id = "1561663077701660672"

    resp = IhrmEmployApi.quary_emp(emp_id, header)
    print("查询",resp.json())

    json_data = {"username": "齐圣"}
    resp = IhrmEmployApi.modify_emp(emp_id, header, json_data)
    print("修改", resp.json())

    resp = IhrmEmployApi.del_emp(emp_id, header)
    print("删除", resp.json())


